<?php
namespace App\Http\Controllers;


class LoginController extends Controller{

    public function index()
    {


        if(\Auth::guard('admin')->user()==null)
        {
            return view('admin.login.index');
        }else{
            return redirect('/admin/home');
        }
    }

    /*
     * 具体登陆
     */
    public function login()
    {


        $this->validate(request(), [
            'name' => 'required|min:2',
            'password' => 'required|min:5|max:10',
        ]);
        $user = request(['name', 'password']);
        if (true == \Auth::guard('admin')->attempt($user)) {
            return array(
                'Status'=>'OK',
                'code'=>$_POST['code']
            );
            //return redirect('/admin/home');
        }

        return array(
            'Status'=>'NO',
            'code'=>$_POST['code']
        );
        //return \Redirect::back()->withErrors("用户名密码错误");
    }

    /*
     * 登出操作
     */
    public function logout()
    {
        \Auth::guard('admin')->logout();
        return redirect('/admin/login');
    }

}